//
//  RegistrationAPI.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/19.
//

import Moya

enum SERegistrationAPI {
    /// 科室列表
    case departMentList(id: String)
    /// 获取时间导航
    case dateList(hospitalId: String,
                  departmentId: String)
    /// 获取医生排班列表
    /// registerType 挂号类别 - 1: 普通, 2: 专家
    case registrationDoctorList(hospitalId: String,
                                deptId: String,
                                startDate: String,
                                endDate: String,
                                registerType: String,
                                doctorName: String,
                                pageNum: Int,
                                pageSize: Int = 10)
    /// 获取号源列表
    case registrationNumList(id: String)
    /// 获取号源价格
    case registrationNumFee(id: String)
    /// 提交号源预约
    case registrationSubmit(sourceId: String, patientId: String, cardType: Int?, cardNum: String?)
    /// 取消号源预约
    case registrationCancel(id: String)
    /// 我的号源列表  id - 号源id 返回唯一
    case myRegistrationList(id: String, pageNum: Int, pageSize: Int, flag: Int = 1)
    /// 医院就诊卡预留手机号不一致 校验验证码
    case checkMsg(code: String, phone: String, patientId: String, hospitalId: String)
}

extension SERegistrationAPI: TargetType {
    var baseURL: URL {
        return URL(string: SEApiManager.baseUrl)!
    }

    var path: String {
        switch self {
        case .departMentList:
            return "/smarteye/smarteye-register/source/general/queryDept"
        case .dateList:
            return "/smarteye/smarteye-register/source/source/timeNav"
        case .registrationDoctorList:
            return "/smarteye/smarteye-register/source/source/queryShift"
        case .registrationNumList:
            return "/smarteye/smarteye-register/source/source/querySource"
        case .registrationNumFee:
            return "/smarteye/smarteye-register/source/source/fee"
        case .registrationSubmit:
            return "/smarteye/smarteye-register/source/source/register"
        case .registrationCancel:
            return "/smarteye/smarteye-register/source/source/unRegister"
        case .myRegistrationList:
            return "/smarteye/smarteye-register/source/source/registerPage"
        case .checkMsg:
            return "/smarteye/smarteye-register/source/patient/checkPhoneCode"
        }
    }

    var method: Moya.Method {
        .post
    }

    var sampleData: Data {
        return "".data(using: .utf8)!
    }

    var task: Task {
        return .requestParameters(parameters: parameters, encoding: JSONEncoding.default)
    }

    var headers: [String : String]? {
        return SEApiManager.headers
    }

    private var parameters: [String: Any] {
        switch self {
        case let .departMentList(id):
            return ["hospitalId": id]
        case let .dateList(hospitalId, departmentId):
            return ["hospitalId": hospitalId,
                    "id": departmentId]
        case let .registrationDoctorList(hospitalId, deptId, startDate, endDate, registerType, doctorName, pageNum, pageSize):
            return ["hospitalId": hospitalId,
                    "deptId":deptId,
                    "startDate": startDate,
                    "endDate": endDate,
                    "registerType": registerType,
                    "doctorName": doctorName,
                    "pageNum": pageNum,
                    "pageSize": pageSize]
        case let .registrationNumList(id):
            return ["id" : id]
        case let .registrationNumFee(id):
            return ["id" : id]
        case let .registrationSubmit(sourceId, patientId, cardType, cardNum):
            return ["sourceId" : sourceId,
                    "patientId": patientId,
                    "cardType": cardType ?? 0,
                    "cardNum": cardNum ?? "",
                    "type": 0]
        case let .registrationCancel(id):
            return ["id" : id]
        case let .myRegistrationList(id, pageNum, pageSize, flag):
            return ["id": id,
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                    "flag": flag]
        case let .checkMsg(code, phone, patientId, hospitalId):
            return ["code": code,
                    "phone": phone,
                    "patientId": patientId,
                    "hospitalId": hospitalId]
        }
    }
}
